layui.define(['myCommon'], function (exports) {
    "use strict";

    let $ = layui.jquery
        , form = layui.form
        , table = layui.table
        , myCommon = layui.myCommon;

    window.confirmAndGet = function (url, id, info, fn) {
        myCommon.msg.confirm(info, function () {
            myCommon.request.get({
                url: url
                , data: {
                    id: id
                }
                , prefix: true
            }, function (res) {
                if ('function' == typeof fn) {
                    return fn(res);
                }
                myCommon.msg.success(res.msg, function () {
                    location.reload();
                });
            });
        });
        return false;
    }

    window.selectMultiAndGet = function (url, confirmInfo, fnCheck) {
        let checkStatus = table.checkStatus('currentTable'),
            data = checkStatus.data, ret;
        if (data.length <= 0) {
            myCommon.msg.error('请选择需要处理的数据');
            return false;
        }
        if ('function' == typeof fnCheck) {
            ret = fnCheck(data);
            if (ret !== true) {
                myCommon.msg.error(ret);
                return false;
            }
        }
        let ids = [];
        $.each(data, function (i, v) {
            ids.push(v.id);
        });
        confirmAndGet(url, ids, confirmInfo, function (res) {
            myCommon.msg.success(res.msg, function () {
                table.reload('currentTable');
            });
        });
        return false;
    };

    window.popupWindow = function (name, url, callback, width, height) {
        if (typeof callback != 'function') {
            callback = function () {
            }
        }
        if (width == null) {
            width = 1200;
        }
        if (height == null) {
            height = 550;
        }
        myCommon.showWindow({
            title: name,
            url: myCommon.url(url),
            dialogWidth: width,
            dialogHeight: height,
            fnCallback: function (ret) {
                callback(ret);
            }
        });
        return false;
    }

    let myApp = {};

    exports('myApp', myApp);
});